home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 9.7 KB | 326 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: EmbedCmd.cpp
- // Release Version: $ 1.0d11 $
- //
- // Author: John Wendt
- //
- // Copyright: © 1993, 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "Embed.hpp"
-
- #ifndef EMBEDCMD_H
- #include "EmbedCmd.h"
- #endif
-
- #ifndef EMBEDSEL_H
- #include "EmbedSel.h"
- #endif
-
- #ifndef EMBEDPXY_H
- #include "EmbedPxy.h"
- #endif
-
- #ifndef EMBEDPAR_H
- #include "EmbedPar.h"
- #endif
-
- #ifndef EMBEDFRA_H
- #include "EmbedFra.h"
- #endif
-
- // ----- Framework Includes -----
-
- #ifndef FWPRESEN_H
- #include "FWPresen.h"
- #endif
-
- // ----- OS Includes -----
-
- #ifndef FWORDCOL_H
- #include "FWOrdCol.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_Module_OpenDoc_Commands_defined
- #include <CmdDefs.xh>
- #endif
-
- //========================================================================================
- // RunTime Info
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment opfEmbed
- #endif
-
- //========================================================================================
- // CEmbedEditCommand
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CEmbedEditCommand constructor
- //----------------------------------------------------------------------------------------
-
- CEmbedEditCommand::CEmbedEditCommand(Environment *ev,
- ODCommandID commandID,
- CEmbedPart* part,
- FW_CFrame* frame,
- FW_CSelection* selection,
- FW_Boolean canUndo) :
- FW_CEditCommand(ev, commandID, frame, canUndo),
- fEmbedPart(part),
- fPastedProxy(NULL),
- fOldProxy(NULL)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CEmbedEditCommand destructor
- //----------------------------------------------------------------------------------------
-
- CEmbedEditCommand::~CEmbedEditCommand()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CEmbedEditCommand::SaveUndoState
- //----------------------------------------------------------------------------------------
- void CEmbedEditCommand::SaveUndoState(Environment* ev) // Override
- {
- if ((fCommandID == kODCommandCut) || (fCommandID == kODCommandClear))
- fPastedProxy = fEmbedPart->GetProxy(ev);
- else if (fCommandID == kODCommandPaste)
- fOldProxy = fEmbedPart->GetProxy(ev);
-
- }
-
- //----------------------------------------------------------------------------------------
- // CEmbedEditCommand::FreeUndoState
- //----------------------------------------------------------------------------------------
- void CEmbedEditCommand::FreeUndoState(Environment* ev) // Override
- {
- if ((fCommandID == kODCommandCut) || (fCommandID == kODCommandClear))
- {
- delete fPastedProxy;
- }
- else if (fCommandID == kODCommandPaste)
- {
- // Delete the original proxy
- delete fOldProxy;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CEmbedEditCommand::SaveRedoState
- //----------------------------------------------------------------------------------------
- void CEmbedEditCommand::SaveRedoState(Environment *ev) // Override
- {
- if (fCommandID == kODCommandPaste)
- fPastedProxy = fEmbedPart->GetProxy(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CEmbedEditCommand::FreeRedoState
- //----------------------------------------------------------------------------------------
- void CEmbedEditCommand::FreeRedoState(Environment* ev) // Override
- {
- if (fCommandID == kODCommandPaste)
- {
- // Delete the pasted proxy
- delete fPastedProxy;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CEmbedEditCommand::UndoIt
- //----------------------------------------------------------------------------------------
- void CEmbedEditCommand::UndoIt(Environment *ev) // Override
- {
- switch (fCommandID)
- {
- case kODCommandCut:
- case kODCommandClear:
- this->RestorePart(ev);
- break;
-
- case kODCommandPaste:
- this->RemovePart(ev);
- this->RestoreOldPart(ev);
- break;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CEmbedEditCommand::RedoIt
- //----------------------------------------------------------------------------------------
- void CEmbedEditCommand::RedoIt(Environment *ev) // Override
- {
- switch (fCommandID)
- {
- case kODCommandCut:
- case kODCommandClear:
- this->RemovePart(ev);
- break;
-
- case kODCommandPaste:
- this->RemovePart(ev);
- this->RestorePart(ev);
- break;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CEmbedEditCommand::RestorePart
- //----------------------------------------------------------------------------------------
- void CEmbedEditCommand::RestorePart(Environment *ev) // Override
- {
- CEmbedSelection* selection = (CEmbedSelection*)fSelection;
-
- fEmbedPart->SetProxy(ev, fPastedProxy);
- fPastedProxy->AttachEmbeddedFrames(ev);
-
- fFrame->GetPresentation(ev)->Invalidate(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CEmbedEditCommand::RemovePart
- //----------------------------------------------------------------------------------------
- void CEmbedEditCommand::RemovePart(Environment *ev) // Override
- {
- // Clear the selection, which includes detaching the proxy frames.
- fSelection->ClearSelection(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CEmbedEditCommand::RestoreOldPart
- //----------------------------------------------------------------------------------------
- void CEmbedEditCommand::RestoreOldPart(Environment* ev)
- {
- // restore the previous part, if any
- if (fOldProxy)
- {
- fEmbedPart->SetProxy(ev, fOldProxy);
- if (fOldProxy)
- fOldProxy->AttachEmbeddedFrames(ev);
-
- // Force a redraw
- fFrame->GetPresentation(ev)->Invalidate(ev);
- }
- }
-
- //========================================================================================
- // class CProxyDropCommand
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CProxyDropCommand constructor
- //----------------------------------------------------------------------------------------
-
- CProxyDropCommand::CProxyDropCommand(Environment* ev,
- CEmbedPart* itsPart,
- FW_CFrame* frame,
- ODDragItemIterator* dropInfo,
- ODFacet* odFacet,
- const FW_CPoint& dropPoint) :
- FW_CDropCommand(ev, (FW_CPart*)itsPart, frame, dropInfo, odFacet, dropPoint, FW_kCanUndo),
- fEmbedPart(itsPart),
- fDroppedProxy(NULL),
- fOldProxy(NULL)
- {
- fEmbedSelection = (CEmbedSelection*) frame->GetPresentation(ev)->GetSelection(ev);
- this->SetMenuStrings(ev, "Undo Drop", "Redo Drop");
-
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // CProxyDropCommand destructor
- //----------------------------------------------------------------------------------------
-
- CProxyDropCommand::~CProxyDropCommand()
- {
- }
-
- //---------------------------------------------------------------------------------------
- // CProxyDropCommand::UndoIt
- //---------------------------------------------------------------------------------------
- void CProxyDropCommand::UndoIt(Environment* ev)
- {
- FW_ASSERT(fDroppedProxy);
-
- // remove the dropped part
- fEmbedSelection->ClearSelection(ev);
-
- // restore the previous part, if any
- fEmbedPart->SetProxy(ev, fOldProxy);
- if (fOldProxy)
- fOldProxy->AttachEmbeddedFrames(ev);
-
- // Force a redraw
- fFrame->GetPresentation(ev)->Invalidate(ev);
- }
-
- //---------------------------------------------------------------------------------------
- // CProxyDropCommand::RedoIt
- //---------------------------------------------------------------------------------------
- void CProxyDropCommand::RedoIt(Environment* ev)
- {
- FW_ASSERT(fDroppedProxy);
-
- // remove the original embedded part
- fEmbedSelection->ClearSelection(ev);
-
- // restore the dropped part
- fEmbedPart->SetProxy(ev, fDroppedProxy);
- fDroppedProxy->AttachEmbeddedFrames(ev);
-
- // Force a redraw
- fFrame->GetPresentation(ev)->Invalidate(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CProxyDropCommand::SaveUndoState
- //----------------------------------------------------------------------------------------
- void CProxyDropCommand::SaveUndoState(Environment *ev)
- {
- // Save the proxy for the part that's currently embedded
- fOldProxy = fEmbedPart->GetProxy(ev);
- }
-
- //---------------------------------------------------------------------------------------
- // CProxyDropCommand::SaveRedoState
- //---------------------------------------------------------------------------------------
- void CProxyDropCommand::SaveRedoState(Environment *ev)
- {
- // Save the proxy for the part that was just dropped
- fDroppedProxy = fEmbedPart->GetProxy(ev);
- }
-
- //---------------------------------------------------------------------------------------
- // CProxyDropCommand::CommitDone
- //---------------------------------------------------------------------------------------
- void CProxyDropCommand::CommitDone(Environment* ev)
- {
- if (fOldProxy)
- {
- // Delete the original proxy
- delete fOldProxy;
- fOldProxy = NULL;
- }
- }
-
- //---------------------------------------------------------------------------------------
- // CProxyDropCommand::CommitUndone
- //---------------------------------------------------------------------------------------
- void CProxyDropCommand::CommitUndone(Environment* ev)
- {
- // Delete the dropped proxy
- delete fDroppedProxy;
- }
-
-
-